package com.strong.utils;

/**
 * 身份证号码工具类
 *
 * @author Administrator
 * @date 2023/04/08
 */
public class IdNumberUtils {
    /**
     * 身份证校验C
     */
    private static final int[] CALC_C = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};

    /**
     * 身份证校验R
     */
    private static final char[] CALC_R = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};

    /**
     * 身份证序号 男性数组
     */
    public final static Integer[] INTS_MALE_NUMBER = {1, 3, 5, 7, 9};

    /**
     * 身份证序号 女性数组
     */
    public final static Integer[] INTS_FEMALE_NUMBER = {0, 2, 4, 6, 8};

    /**
     * 获取校验码
     *
     * @param sbIdNumber 某人身份证号
     * @return char
     */
    public static char getCheckCode(StringBuilder sbIdNumber) {
        int[] n = new int[17];
        int result = 0;
        for (int i = 0; i < n.length; i++) {
            n[i] = Integer.parseInt(String.valueOf(sbIdNumber.charAt(i)));
        }
        for (int i = 0; i < n.length; i++) {
            result += CALC_C[i] * n[i];
        }
        return CALC_R[result % 11];
    }
}